<PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
<title>YUI IO Event Facade Tests</title>
</head>

<body class="yui3-skin-sam">
<h1>IO Event Facade Tests</h1>

<script type="text/javascript" src="../../../build/yui/yui.js"></script>
<script type="text/javascript">

(function() {
    YUI({
        base: "../../../build/",
        filter: "debug",
        logExclude: {
            attribute: true,
            dom: true,
            node: true,
            event: true,
            base: true,
            widget: true,
            selector: true,
            io:true
        },
        useConsole: true
    }).use("test", "console", "io-base", function(Y) {

        var console = new Y.Console().render(),
			io = new Y.IO( { emitFacade: 1 }),
			id = 0, cfg;

		function se(o) {
			Y.Assert.isObject(o);
			Y.Assert.isObject(o.cfg);
			Y.Assert.isNumber(o.id);				
			Y.Assert.isUndefined(o.data.status);
			Y.Assert.isUndefined(o.data.statusText);
			Y.Assert.isUndefined(o.data.responseText);
			Y.Assert.isString(o.arguments);
		}

		function csf(o) {
			Y.Assert.isObject(o);
			Y.Assert.isObject(o.cfg);
			Y.Assert.isNumber(o.id);				
			Y.Assert.isNumber(o.data.status);
			Y.Assert.isString(o.data.statusText);
			Y.Assert.isString(o.data.responseText);
			Y.Assert.isFunction(o.data.getResponseHeader);
			Y.Assert.isFunction(o.data.getAllResponseHeaders);
			Y.Assert.isString(o.arguments);
		}

		cfg = {
			on: {
				start: se,
				complete: csf,
				end: se,
				success: csf,
				failure: csf
			 },
			arguments: 'foo=bar'
		};
		o1 = {
			id: + id,
			c: {
				status: undefined,
				statusText: undefined,
				responseText: undefined,
				responseXML: undefined,
			}
		};
		o2 = {
			id: + id,
			c: {
				responseText: 'Hello World',
				responseXML: null,
				getResponseHeader: function() { },
				getAllResponseHeaders: function() { }	
			}
		};

        var io_facade_se = new Y.Test.Case({
            name: 'Test IO Start Event Facade',
            'test': function() {		
				io._evt('start', o1, cfg);
            }
        });

        var io_facade_complete = new Y.Test.Case({
            name: 'Test IO Complete, Success Event Facade',
            'test': function() {
				o2.c.status = 200;
				o2.c.statusText = 'OK';
				io._evt('complete', o2, cfg);
            }
        });

        var io_facade_failure = new Y.Test.Case({
            name: 'Test IO Failure Event Facade',
            'test': function() {
				o2.c.status = 500;
				o2.c.statusText = 'Server Error';
				io._evt('complete', o2, cfg);
            }
        });

	Y.Test.Runner.add(io_facade_se);
	Y.Test.Runner.add(io_facade_complete);
	Y.Test.Runner.add(io_facade_failure);
	Y.Test.Runner.run();
});
})();
</script>
</body>
</html>